<div class="add"><%= link_to 'إضافة شخص ', new_person_path %></div>
<table class="listTable">
  <thead>
    <tr>
      <th>الاسم</th>
      <th>الرقم القومي</th>
      <th>إلغاء</th>
      <th>إعطاء</th>
    </tr>
  </thead>
  <tbody>
    <% @people.each do |person| %>
    <tr>
      <td class="name"><%= link_to person.name, person %></td>
      <td><%= person.national_id %></td>
      <td>
        <%= link_to 'تعديل', edit_person_path(person) %> | 
        <%= link_to 'إلغاء', person, method: :delete, data: { confirm: 'Are you sure?' } %>
      </td>
      <% unless person.bags.empty? %>
        <td><%= person.bags.last.updated_at.to_formatted_s(:long_ordinal) %></td>
      <% else %>
        <td>لم يستلم بعد</td>
      <% end %>
      <% unless @number_of_bags == 0 %>
        <td  class="tableCheck">
          <%= form_for person, html: {multipart: true}, remote: true do |f| %>
            <%= f.check_box :give, class: "give" %>
            <%= image_tag "loading.gif", :class => "loading", :style => "display: none;" %>
          <% end %>
        </td>
      <% end %>
    </tr>
    <% end %>
  </tbody>
</table>
<%= javascript_tag do %>
  $(function()
  {
    $("input:checkbox.give").change(function()
    {
      $(this).parents("form").submit().children().hide().end().find("img.loading").show();
    });
  });
<% end %>